import { createApp } from 'vue';
import { createPinia } from 'pinia';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import './style.css';
import './assets/responsive.css'; // 引入全局响应式CSS
import App from './App.vue';
import router from './router';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import { useAuthStore } from './stores/auth';

const app = createApp(App);
const pinia = createPinia();

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

// 使用插件
app.use(pinia);
app.use(router);
app.use(ElementPlus);

// 应用启动时验证认证状态
async function initApp() {
  const authStore = useAuthStore();
  await authStore.validateToken();
  app.mount('#app');
}

initApp();